#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author:jidi
@file:calendar_http_api.py
@time:2022/08/14
"""
from dataclasses import asdict

import requests

from service.wework.model.calendar import Calendar
from service.wework.model.calendar_api import CalendarApi
from service.wework.model.schedule import Schedule


class CalendarHttpApi(CalendarApi):
    def add_schedule(self, schedule: Schedule):
        r = requests.post(
            'https://qyapi.weixin.qq.com/cgi-bin/oa/schedule/add',
            params={'access_token': self.session.get_token()},
            json={
                'schedule': asdict(schedule)
            }
        )
        return r

    def add(cls, calendar: Calendar):
        ...
